package com.als.healthymananger.controller.impl;

import com.als.healthymananger.controller.AssessmentsApi;
import com.als.healthymananger.entity.Assessment;
import com.als.healthymananger.service.AssessmentsService;
import com.als.healthymananger.utils.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/assessment")
public class AssessmentsController implements AssessmentsApi {
    @Autowired
    private AssessmentsService assessmentsService;

    @Override
    public RespBean createAssessments(Assessment assessment) {
        return assessmentsService.save(assessment)? RespBean.ok("添加成功"): RespBean.badRequest("添加失败");
    }

    @Override
    public RespBean deleteAssessments(int assessmentId) {
        return assessmentsService.removeById(assessmentId)? RespBean.ok("删除成功"): RespBean.badRequest("删除失败");
    }

    @Override
    public RespBean updateAssessments(int assessmentId, Assessment assessment) {
        return assessmentsService.updateById(assessment)? RespBean.ok("修改成功"): RespBean.badRequest("修改失败");
    }

    @Override
    public RespBean getAssessments(int assessmentId) {
        Assessment assessment = assessmentsService.getById(assessmentId);
        return assessment == null? RespBean.badRequest("获取失败"): RespBean.ok("获取成功", assessment);
    }
}
